//version 1.1
/*
 * 图片渐隐效果
 */
jQuery(function () {
	jQuery('.thumbnail img').hover(function () {
		jQuery(this).fadeTo("fast", 0.5);
	}, function () {
		jQuery(this).fadeTo("fast", 1);
	});
});

/*
 *
 * 回到头部
 *
 */
$(function () {
	var backTop = function (btnId) {
		var btn = document.getElementById(btnId);
		var d = document.documentElement;
		var b = document.body;
		window.onscroll = set;
		btn.onclick = function () {
			btn.style.display = "none";
			window.onscroll = null;
			this.timer = setInterval(function () {
				d.scrollTop -= Math.ceil((d.scrollTop + b.scrollTop) * 0.1);
				b.scrollTop -= Math.ceil((d.scrollTop + b.scrollTop) * 0.1);
				if ((d.scrollTop + b.scrollTop) == 0)
					clearInterval(btn.timer, window.onscroll = set);
			}, 10);
		};
		function set() {
			btn.style.display = (d.scrollTop + b.scrollTop > 100) ? 'block' : "none";
		}
	};
	backTop('gotop');
});

/*
 * 导航条下拉时收缩
 */
$(function () {
	var index = 100;
	$(window).scroll(function () {
		var top = $(document).scrollTop();
		if (top > index) {
			$('#topNav').children('.logo').hide();
			$('#header').addClass('ui-header-scroll');
			$('.ui-top-nav').addClass('ui-top-nav-scroll');
		}
		else {
			$('#topNav').children('.logo').show();
			$('#header').removeClass('ui-header-scroll');
			$('.ui-top-nav').removeClass('ui-top-nav-scroll');
		}
	});
});


/* * *
 *
 *触发评论模块
 *
 */
$(document).ready(function () {
	if ($('#comment_display').length > 0) {
		(function () {
			var com_sc = document.createElement('script');
			com_sc.type = 'text/javascript';
			com_sc.async = true;
			com_sc.src = 'http://static.siyanjing.net/js/siyanjing/comment.min.js';
			(document.getElementsByTagName('head')[0] ||
				document.getElementsByTagName('body')[0]).appendChild(com_sc);
		})();
	}

});

/**
 * 封装表单数据为json
 */
(function ($) {
	$.fn.serializeJson = function () {
		var serializeObj = {};
		var array = this.serializeArray();
		var str = this.serialize();
		$(array).each(function () {
			if (serializeObj[this.name]) {
				if ($.isArray(serializeObj[this.name])) {
					serializeObj[this.name].push(this.value);
				} else {
					serializeObj[this.name] = [serializeObj[this.name], this.value];
				}
			} else {
				serializeObj[this.name] = this.value;
			}
		});
		return serializeObj;
	};
})(jQuery);
